package com.leo.ktvplayer.ui.setting;

import android.bluetooth.BluetoothDevice;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.leo.ktvplayer.R;
import com.leo.ktvplayer.base.App;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LeoLu on 2017/5/3.
 */

public class BluetoothResultAdapter extends BaseAdapter {
    ArrayList<BluetoothDevice> devices;

    public BluetoothResultAdapter(ArrayList<BluetoothDevice> devices){
        this.devices =devices;
    }

    @Override
    public int getCount() {
        return devices.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if (convertView == null) {
            //TODO
            convertView = LayoutInflater.from(App.getInstance()).inflate(R.layout.item_bluetooth_scan_result,null);
            viewHolder = new ViewHolder();
            viewHolder.bleMacAddress = (TextView) convertView.findViewById(R.id.tv_item_bluetooth_scan_result_macaddress);
            viewHolder.bleName = (TextView)convertView.findViewById(R.id.tv_item_bluetooth_scan_result_blename);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.bleName.setText(devices.get(position).getName());
        viewHolder.bleMacAddress.setText(devices.get(position).getAddress());
        return convertView;
    }

    static class ViewHolder{
        TextView bleName;
        TextView bleMacAddress;
    }
}
